var qcloud = require('../../vendor/sdk/index');
var config = require('../../config');
const app = getApp();

Page({
  data: {
    webViewUrl: null,
    navH: app.globalData.navHeight,
    videoUrl: null,
    title: 'movie'
  },
  onLoad(option) {
    console.log('webview onload', option);
    console.log('video-url', decodeURIComponent(option.videourl));
    let title = option.title;
    let videoIndex = option.videoIndex;
    let sourceUrl = option.sourceUrl;
    if (title && title.length >= 6) {
      title = title.substr(0, 6) + '...';
    }
    this.getSourcePlayUrl(videoIndex, sourceUrl);
    this.setData({
      // videoUrl: decodeURIComponent(option.videourl),
      title: title
    });
  },
  onNavBack() {
    // 返回
    wx.navigateBack();
  },
  getSourcePlayUrl(videoIndex, sourceUrl) {
    let self = this;
    // 获取video视频源地址
    qcloud.request({
      url: config.service.getSourcePublishPlayUrl,
      data: {
        videoIndex: videoIndex,
        sourceUrl: sourceUrl
      },
      success: res => {
        console.log('getSourcePlayUrl-res', res);
        self.setData({
          videoUrl: res.data.data,
        })
      }
    });
  }
});
